<template>
  <el-menu class="el-menu-vertical-demo"
           :default-active="activeIndex"
           router
           unique-opened
           @open="handleOpen"
           @close="handleClose"
           background-color="#545c64"
           text-color="#fff"
           active-text-color="#ffd04b">
    <el-submenu v-for="item in menus" :index="item.id" :key="item.id">
      <template slot="title">
        <i :class="item.IconClass"></i>
        <span v-text="item.MenuName"></span>
      </template>
      <el-menu-item-group class="over-hide" v-for="ChildItem in item.MenuChild" :index="item.id-ChildItem.id"
                          :key="ChildItem.componentName">
        <el-menu-item :index="ChildItem.componentName" v-text="ChildItem.name"></el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<style scoped>
  .over-hide {
    overflow: hidden;
  }
</style>

<script>
  import menus from '@/config/menu-config'

  export default {
    name: 'Menu',
    data() {
      return {
        menus,
        activeIndex:'1'
      }
    },
    methods: {
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      },
    },
    created() {
      for (let i=0;i<this.menus.length;i++){
        let item = this.menus[i];
        item['id'] = String(i+1);
      }
    }
  }
</script>
